package targetToOffer.sixteenthDay;

/**
 * @author Godc
 * @description
 */
public class HammingWeight {
    public static void main(String[] args) {
        System.out.println(Integer.toBinaryString(1));
        System.out.println(Integer.toBinaryString(-1));
        System.out.println(2|2);
    }
}
class HammingWeightSolution {
    // you need to treat n as an unsigned value
    public int hammingWeight(int n) {
        int cnt = 0;
        while(n!=0){
            if((n&1)==1) cnt++;
            // 逻辑右移，高位补0
            n = n>>>1;
        }
        return cnt;
    }
    public int hammingWeight1(int n){
        int cnt = 0;
        while (n!=0){
            cnt++;
            n&=(n-1);
        }
        return cnt;
    }
}